package com.example.to_dolist;


import android.os.Bundle;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

public class MainActivity2 extends Activity implements OnClickListener{
	Button m_addTo_DoListItem; 
	EditText m_editText; 
	View m_itemListView; 
	String ToDoItem;
	RadioButton m_High;
	RadioButton m_Medium;
	RadioButton m_Low;
	int Priority;
	int ctr =0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_activity2);
		initLayout();
		m_addTo_DoListItem.setOnClickListener(this);
	}
	public void findPri(){
		if (m_High.isChecked()){Priority =0 ;}
    else if(m_Medium.isChecked()){Priority = 1;}
    else if(m_Low.isChecked()){Priority =2;}}
	
	public void addToDoItem(){
		//ToDoItem newItem = new ToDoItem(0, ToDoItem);	
		TextView newItemTextView = new TextView(this);
		findPri();
		ToDoItem completeItem = new ToDoItem(Priority, ToDoItem);
		//newItemTextView.setText(newItem);
	newItemTextView.setText(completeItem.GetPriority() + completeItem.GetToDoItem());
		newItemTextView.setTextColor(getResources().getColor(R.color.Red));
		ctr += 1; 
		if (ctr%2 == 0){newItemTextView.setBackgroundColor(getResources().getColor(R.color.dark));
		}
		else{	newItemTextView.setBackgroundColor(getResources().getColor(R.color.light));
		}
		Intent returnIntent = new Intent();
		returnIntent.putExtra(newItemTextView.toString(),1234567);
		setResult(RESULT_OK, returnIntent);
		try {
		    startActivity(returnIntent);
		} catch (ActivityNotFoundException e) {
		    // Display some sort of error message here.
		}
		//ToDoItem = m_editText.getText().toString();
      	//addToDoItem();
    	
		m_editText.setText("");
		finish();
		//((ViewGroup) m_itemListView).addView(newItemTextView);
	}

	
	public void initLayout(){
		m_addTo_DoListItem = (Button) this.findViewById(R.id.button1);
		m_editText = (EditText) this.findViewById(R.id.editText1);
		m_itemListView = (LinearLayout) this.findViewById(R.id.To_Do_List_View);
		m_High = (RadioButton) this.findViewById(R.id.radio0);
		m_Medium =(RadioButton) this.findViewById(R.id.radio1);;
		m_Low= (RadioButton) this.findViewById(R.id.radio2);
		
		}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main_activity2, menu);
		return true;
	}
	
	@Override
	public void onClick(View v) {
		addToDoItem();
		// TODO Auto-generated method stub
	}

	
}
